package com.linxz.wandnroid.appui;

import android.view.KeyEvent;
import android.view.View;

import com.linxz.framework.base.BaseMVPFragment;
import com.linxz.framework.ui.LinxzWebView;
import com.linxz.ui.pojo.BannerBean;
import com.linxz.ui.widgets.LinxzRefreshLayout;
import com.linxz.wandnroid.R;
import com.linxz.wandnroid.appui.view.SystemView;
import com.linxz.wandnroid.pojo.resp.WanAndroidNavigationListResp;
import com.linxz.wandnroid.presenter.SystemPresenter;
import java.util.List;

/**
 * @author Linxz
 * 创建日期：2020年02月20日 23:27
 * version：v4.5.4
 * 描述：
 */
public class SystemFragment extends BaseMVPFragment<SystemPresenter> implements SystemView {

    private LinxzRefreshLayout layoutRefresh;
    private LinxzWebView webView;

    public static SystemFragment newInstance(){
        return new SystemFragment();
    }

    @Override
    protected SystemPresenter createPresenter() {
        return new SystemPresenter(this,lifecycleSubject);
    }

    @Override
    public Object setLayout() {
        return R.layout.wandroid_frag_system;
    }

    @Override
    public void initUI() {
        layoutRefresh=findViewById(R.id.layoutRefresh);
         webView=findViewById(R.id.webView);
    }

    @Override
    public void initData() {
        webView.loadUrl("https://www.wanandroid.com");
    }

    @Override
    public void setListener() {
        super.setListener();
        layoutRefresh.setOnRefreshListener(new LinxzRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                layoutRefresh.finishRefresh();
                initData();
            }
        });
        webView.getWebView().setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                //防止执行多次
                if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount()==0 && event.getAction()==KeyEvent.ACTION_DOWN){
                   return webView.goBack();
                }
                return false;
            }
        });
    }

    @Override
    public void onLoadDataSuccess(List<BannerBean> bannerBeans, List<WanAndroidNavigationListResp.DataBean> navigationTittleBeans) {

    }

    @Override
    public void onLoadDataError(String message) {
    }

    @Override
    public void onDataEmpty() {
    }


}
